# -*- coding: utf-8 -*-
#
# encode-xvid - Encode de vídeos em formato mpeg4 (xvid)/mp3
# URLs: http://code.google.com/p/encode-xvid/, http://estacaozn.blogspot.com
# Copyright 2011 Felipe Guerço Oliveira - felipeguerco@gmail.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Diálogo de log da execução

import gtk

class LogWindow(gtk.Window):
	# campos da tela
	txt_log = gtk.TextView()

	def __init__(self):
		gtk.Window.__init__(self)
		
		self.set_title("Log de execução")
		self.set_default_size(500, 350)

		self.txt_log.set_editable(False)
		self.txt_log.set_cursor_visible(False)

		vbox = gtk.VBox()
		self.add(vbox)

		sw = gtk.ScrolledWindow()
		sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
		sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		sw.add(self.txt_log)

		vbox.add(sw)


	def show_dialog(self):
		self.set_position(gtk.WIN_POS_CENTER)
		self.show_all()

	def add_line(self, line):
		if not line.endswith("\n"):
			line += "\n"
		
		buf = self.txt_log.get_buffer()
		it = buf.get_end_iter()
		buf.insert(it, line)

		self.refresh()

	# rotina para dar refresh na tela enquanto está ocorrendo processamento
	def refresh(self):
		while gtk.events_pending():
			gtk.main_iteration(False)

